package org.domeos.framework.api.mapper.domeos.productline;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.domeos.framework.api.model.productline.ProductLine;
import org.domeos.framework.api.model.productline.ProductLineTree;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

@Mapper
public interface ProductLineMapper {
	
	@Insert("insert into product_line (id, pId, name, description, level,env)" +
            " values (#{id}, #{pId}, #{name}, #{description}, #{level},#{env})")
	@CacheEvict(cacheNames="product_line_cache",beforeInvocation=true)
    int insertRecord(ProductLine record);
	
	@Update("update product_line" +
            " SET description=#{description}, pId=#{pId}," +
            " name=#{name}, level=#{level} ,env=#{env} WHERE id=#{id}")
	@CachePut(cacheNames="product_line_cache")
    int updateRecord(ProductLine record);
	
	@Select("select * from product_line WHERE id=#{id}")
	ProductLine selectById(int id);
	
	@Select("select count(id) from product_line WHERE id=#{id}")
	int getCountById(int id);
	
	@Select("select id,CONCAT(NAME,description) AS title,level,env,pId  from product_line WHERE level=#{level}")
	@Cacheable(cacheNames="product_line_cache")
	List<ProductLineTree> selectByLevel(int level);

	@Select("select id,CONCAT(NAME,description) AS title,level,env,pId from product_line WHERE pId=#{pId}")
	@Cacheable(cacheNames="product_line_cache")
	List<ProductLineTree> selectByPId(int pId);
}
